//
//  AppDelegate.swift
//  TimeBoat
//
//  Created by bo wang on 2022/8/23.
//  Copyright © 2022 Time Boat. All rights reserved.
//

import Foundation
var APP : AppDelegate = UIApplication.shared.delegate as! AppDelegate
@main
@objc
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    @objc static var shared: AppDelegate!
    @objc var tuic:Bool = false
    private var launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    
    override private init() {
        super.init()
        Self.shared = self
    }
    
    lazy var window: UIWindow? = {
        let window = UIWindow(frame: UIScreen.main.bounds)
        window.backgroundColor = .black
        return window
    }()
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
        self.launchOptions = launchOptions
        window?.makeKeyAndVisible()
        if #available(iOS 13, *) {
            window?.overrideUserInterfaceStyle = .light
        }
        AppDelegateBridging.shared().showStyle()
        AppDelegateBridging.shared().configIQKeyBoard()
        AppDelegateBridging.shared().judgeLoginOrTab()
        
        ConfigManager.shared.start()
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            BTLEBaseDataManager.shared.start()
            BTLESendDataManager.shared.start()
            TCPSendDataManager.shared.start()
        }
        
        return true
    }
    
    func onLoginInvalid() {
        AccountManager.shareAccount().logout()
        AppDelegateBridging.shared().setupLoginVC()
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        return WXApi.handleOpen(url, delegate: LoginUtils.shareManager())
    }
    
    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        return WXApi.handleOpenUniversalLink(userActivity, delegate: LoginUtils.shareManager())
    }
}
